import json
import time

try:
    # 读取并打印原始内容
    with open('cookie.txt', 'r') as file:
        headers = json.load(file)
    # print("原始内容:")
    # print(json.dumps(headers, indent=4, ensure_ascii=False))
    
    # 修改时间戳
    cookie_parts = headers["Cookie"].split('_')
    if len(cookie_parts) > 1:
        new_timestamp = str(int(time.time() * 1000))
        new_cookie = cookie_parts[0] + '_' + new_timestamp+"; "+cookie_parts[1].split(';', 1)[1]
        headers["Cookie"] = new_cookie

    # # 打印修改后的内容
    # print("\n修改后内容:")
    # print(json.dumps(headers, indent=4, ensure_ascii=False))

    # 可选：将修改后的内容写回文件
    with open('cookie.txt', 'w') as file:
        json.dump(headers, file, indent=4)
except FileNotFoundError:
    print("文件不存在，请检查路径")
except Exception as e:
    print(f"读取文件时出错: {e}")